/***********************************************
* Filename:  		WinM_InputHandler.cpp
* Date:      		01/12/2014
* Mod. Date: 		01/12/2014
* Author:    		Night
* Purpose:   		Handles keyboard input based
					on Windows Messages.
					Uses VIK key codes for input.
					VIK Reference: http://msdn.microsoft.com/en-us/library/windows/desktop/dd375731(v=vs.85).aspx
************************************************/
#include "WinM_InputHandler.h"
#include <Windows.h>

#if _DEBUG
#include <cassert>
#endif

CWinM_InputHandler::CWinM_InputHandler( void )
{

};

CWinM_InputHandler::~CWinM_InputHandler( void )
{

};

CWinM_InputHandler *CWinM_InputHandler::GetInstance( void )
{
	static CWinM_InputHandler instance;
	return &instance;
};

void CWinM_InputHandler::Init( void )
{
	ZeroMemory( m_cInputBuffer, sizeof( m_cInputBuffer ) );
	ZeroMemory( m_cPrevInputBuffer, sizeof( m_cPrevInputBuffer ) );
};

void CWinM_InputHandler::Release( void )
{
	ZeroMemory( m_cInputBuffer, sizeof( m_cInputBuffer ) );
	ZeroMemory( m_cPrevInputBuffer, sizeof( m_cPrevInputBuffer ) );
};

void CWinM_InputHandler::Update( void )
{
	memcpy( m_cPrevInputBuffer, m_cInputBuffer, sizeof( m_cInputBuffer ) );
	//ZeroMemory( m_cInputBuffer, sizeof( m_cInputBuffer ) );
};

bool CWinM_InputHandler::CheckKeyDown( const unsigned char _cKey )
{
#if _DEBUG
	if( _cKey < 0 || _cKey >= sizeof( m_cInputBuffer ) )
		assert( !"Input Key out of range!" );
#endif

	return ( m_cInputBuffer[_cKey] ? true : false );
};

bool CWinM_InputHandler::CheckKeyUp( const unsigned char _cKey )
{
#if _DEBUG
	if( _cKey < 0 || _cKey >= sizeof( m_cInputBuffer ) )
		assert( !"Input Key out of range!" );
#endif

	return ( ( m_cPrevInputBuffer[_cKey] && !m_cInputBuffer[_cKey] ) ? true : false );
};

bool CWinM_InputHandler::CheckKeyPressed( const unsigned char _cKey )
{
#if _DEBUG
	if( _cKey < 0 || _cKey >= sizeof( m_cInputBuffer ) )
		assert( !"Input Key out of range!" );
#endif

	return ( ( !m_cPrevInputBuffer[_cKey] && m_cInputBuffer[_cKey] ) ? true : false );
};

void CWinM_InputHandler::Acion_PressKey( const unsigned char _cKey )
{
#if _DEBUG
	if( _cKey < 0 || _cKey >= sizeof( m_cInputBuffer ) )
		assert( !"Input Key out of range!" );
#endif

	m_cInputBuffer[_cKey] = 1;
};

void CWinM_InputHandler::Acion_UnPressKey( const unsigned char _cKey )
{
#if _DEBUG
	if( _cKey < 0 || _cKey >= sizeof( m_cInputBuffer ) )
		assert( !"Input Key out of range!" );
#endif

	m_cInputBuffer[_cKey] = 0;
};
